<#--给部署人员查看回路号的界面-->
<#assign baseURL = springMacroRequestContext.getContextPath() />
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>拓深科技</title>

    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="assets/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="assets/css/plugins/dataTables/dataTables.responsive.css" rel="stylesheet">
    <link href="assets/css/plugins/dataTables/dataTables.tableTools.min.css" rel="stylesheet">
    <link href="assets/css/animate.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/img/log.ico" rel="shortcut icon">
    <style>
        body
        {
            background-color:#FFFFFF;
        }
    </style>
</head>
<body>
<div id="wrapper" class="gray-bg" style="background-color:#FFFFFF;">
    <div class="col-lg-12" style="background-color:#FFFFFF;margin-top: 10px;margin-bottom: 10px;">
        <div class="col-lg-2">
            <button id="deleteAllBtn" type="button" class="btn btn-block btn-danger"><i class="fa fa-trash"></i>&nbsp;全部删除</button>
        </div>
        <div class="col-lg-2">
            <button id="refreshAllBtn" type="button" class="btn btn-block btn-info"><i class="fa fa-spinner"></i>&nbsp;刷新</button>
        </div>
    </div>
    <div class="ibox-content">
        <table class="table table-striped table-bordered table-hover " id="alarmLogTable" cellspacing="0" width="100%">
            <thead>
            <tr>
                <th style="display: none">ID</th>
                <th>报警IP</th>
                <th>报警回路号</th>
                <th>上传的传感器类型</th>
                <th>上传的报警类型</th>
                <th>报警时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
    </div>
</div>


<!-- Mainly scripts -->
<script src="assets/js/jquery-2.1.1.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<#--已修改-->
<script src="assets/js/plugins/pace/pace.min.js"></script>
<!-- Data Tables -->
<script src="assets/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="assets/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="assets/js/plugins/dataTables/dataTables.responsive.js"></script>
<script src="assets/js/plugins/dataTables/dataTables.tableTools.min.js"></script>

<script>
    var alarmLogTable = $('#alarmLogTable').DataTable({
        language: {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        },
        ajax: "${baseURL}/dev/getAll",
        columns:[
            {"data":"ip"},
            {"data":"dev_addr"},
            {"data":"dev_type"},
            {"data":"dev_status","render":function(data, type, row, meta){
                return (data);
            }},
            {"data":"alarm_time","render":function(data, type, row, meta){
                return showTime(data);
            }},
            {"data":"id","render":function(data, type, row, meta){
                return '<button type="button" class="btn btn-block btn-danger" onclick="deleteBtn('+ row.id +')"  style="padding: 0 0 0 0"><i class="fa fa-trash"></i>&nbsp;删&nbsp;&nbsp;除</button>';
            }}
        ],
        destroy: true,
        serverSide: false
    });

    function deleteBtn(id){
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            url: "${baseURL}/dev/delete?id=" + id,
            success:function(data){
                if(data.code === 0){
                    alarmLogTable.ajax.reload();
                }
            },
            error:function(xhr, status, error){
                console.log(xhr.responseText);
            }
        });
    }

    function showTime(unix_time) {
        var date = new Date(unix_time * 1000);
        var year = date.getFullYear().toString();
        var month = (date.getMonth() + 1).toString();
        if(month.length < 2) month = '0' + month;
        var day = date.getDate().toString();
        if(day.length < 2) day = '0' + day;
        var h = date.getHours().toString();
        if(h.length < 2) h = '0'+ h;
        var m = date.getMinutes().toString();
        if(m.length < 2) m = '0'+ m;
        var s = date.getSeconds().toString();
        if(s.length < 2) s = '0'+ s;
        return year + '-' + month + '-' + day + ' ' + h + ":" + m +":" + s;
    }

    $("#deleteAllBtn").click(function(){
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            url: "${baseURL}/dev/deleteAll",
            success:function(data){
                if(data.code === 0){
                    alarmLogTable.ajax.reload();
                }
            },
            error:function(xhr, status, error){
                console.log(xhr.responseText);
            }
        });
    });

    $("#refreshAllBtn").click(function(){
        alarmLogTable.ajax.reload();
    });

</script>
</body>
</html>